__all__ = ["get_framerate", "time_to_frames", "frames_to_timecode"]

import pymel.core as pc

def get_framerate():
    dic = {
            "film": 24,
            "pal": 25,
            "ntsc": 30
        }
    return dic.get(pc.currentUnit(time=True, q=True), 24)

def time_to_frames(timecode):
    framerate = get_framerate()
    return sum(f * int(t) for f,t in zip((3600*framerate, 60*framerate, framerate, 1), timecode.split(':')))


def frames_to_timecode(frames):
    framerate = get_framerate()
    return '{0:02d}:{1:02d}:{2:02d}:{3:02d}'.format(frames / (3600*framerate),
                                                    frames / (60*framerate) % 60,
                                                    frames / framerate % 60,
                                                    frames % framerate)